package view.panel.prompt
{
	import control.panel.IPanelControl;
	import control.panel.prompt.ServerPromptPanelControl;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import global.GameState;
	import global.GameType;
	
	import utils.DisplayTool;
	import utils.TextTool;
	
	import view.components.ImgButton;
	import view.panel.AbsPanel;
	
	public class ServerPromptPanel extends AbsPanel
	{
		private var hintText:TextField;
		private var yesBut:ImgButton;
		private var noBut:ImgButton;
		public static var tempText:TextField;
		
		public function ServerPromptPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			defaultX = GameState.GAME_WIDTH / 2;
			defaultY = GameState.GAME_HEIGHT / 2;
			initText();
			initButs();
			initTweenPanelOpen();
		}
		
		private function initButs():void
		{
			yesBut = new ImgButton(0,0,GameType.BUTTON_YES,onBut,50,20,"butBg",null,"确 定");
			noBut = new ImgButton(0,0,GameType.BUTTON_NO,onBut,50,20,"butBg",null,"取 消");
		}
		
		private function onBut(event:MouseEvent):void
		{
			(this.panelControl as ServerPromptPanelControl).onBut(event.target.id);
			close();
		}
		
		private function initText():void
		{
			hintText = TextTool.getTextField(200,20,12,0xFFFFFF);
			hintText.x = 10;
			hintText.y = 5;
			hintText.multiline = true;
			hintText.wordWrap = true;
			tempText = new TextField();
			tempText.width = 1000;
		}
		
		public function update(content:String):void
		{
			DisplayTool.removeChild(this,hintText);
			DisplayTool.removeChild(this,yesBut);
			DisplayTool.removeChild(this,noBut);
			
			hintText.htmlText = content;
			tempText.htmlText = content;
			hintText.width = tempText.textWidth + 5;
			if (hintText.width < 300)
			{
				hintText.width = 300;
			}
			else if (hintText.width > 400)
			{
				hintText.width = 400;
			}
	
			
			hintText.height = hintText.textHeight + 5;
			
			if (hintText.height < 40)
			{
				hintText.height = 40;
			}

			resetBg(hintText.width + 20,hintText.height + 40);
			
		}
		
		private function resetButs():void
		{
			yesBut.x = width / 2 - yesBut.width - 20;
			noBut.x = width / 2  + 20;
			noBut.y = yesBut.y = hintText.height ;
			addChild(yesBut);
			addChild(noBut);
			addChild(hintText);
		}
		
		private function setYCenter():void
		{
			defaultY = (430 - this.height ) * .5;
			defaultX = (GameState.GAME_WIDTH - this.width) * .5; 
			resetButs();
		}
		
		override public function open() : void
		{
			setYCenter();
			
			super.open();
		}
	}
}